﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE HTML>
<html>
<head>

<%@ include file="/common/meta.jsp"%>
<%@ include file="/common/links.jsp"%>

<script type="text/javascript">
	var dailog;
	function demoEntityAdd() {
		dailog = $.ligerDialog.open({
			url : 'addEntity',
			height : 700,
			width : 600,
			isResize : true,
			showMax : true,
			showToggle : true,
			showMin : false,
			modal : false
		});
	}
	function demoEntityEdit() {
		var id = grid.selrow("demoId");
		if (!id) {
			$.ligerDialog.warn('请选择一条记录。');
			return;
		}
		var url = 'editEntity?id=' + id;
		dailog = $.ligerDialog.open({
			url : url,
			height : 700,
			width : 600,
			isResize : true,
			showMax : true,
			showToggle : false,
			showMin : false,
			modal : false
		});
	}

	function demoEntityDelete() {
		var rows = grid.getCheckedRows();
		if (rows.length < 1) {
			$.ligerDialog.warn('请至少选择一条记录。');
			return;
		}
		var sid = grid.selarrrow();
		$.ligerDialog.confirm('确定删除选定记录吗?', function(yes) {
			var url = "deleteEntity?ids=" + sid;
			var jqxhr = jQuery.post(url, {
				dataType : "json"
			}).success(function(data) {
				if (data.ajaxStatus === "success") {
					var m = jQuery.ligerDialog.tip({
						title : '提示信息',
						content : data.ajaxMessage
					});
					setTimeout(function() {
						m.hide();
					}, 5000);
					grid.loadData();
				} else {
					$.ligerDialog.error(data.ajaxMessage);
				}

			});
		});
	}

	$.ligerDefaults.Grid.formatters['currency'] = function(num, column) {
		if (!num)
			return "$0.00";
		num = num.toString().replace(/\$|\,/g, '');
		if (isNaN(num))
			num = "0.00";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num * 100 + 0.50000000001);
		cents = num % 100;
		num = Math.floor(num / 100).toString();
		if (cents < 10)
			cents = "0" + cents;
		for ( var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
			num = num.substring(0, num.length - (4 * i + 3)) + ','
					+ num.substring(num.length - (4 * i + 3));
		return "$" + (((sign) ? '' : '-') + '' + num + '.' + cents);
	};
	$.ligerDefaults.Grid.formatters['boolean'] = function(num, column) {
		try {
			if (num == "true" || num == "1")
				return "√";
			else
				return "×";
		} catch (e) {
			alert(e.message);
		}
	};
	$.ligerDefaults.Grid.formatters['datetime'] = function(num, column) {
		try {
			alert(num);
			return num;
		} catch (e) {
			alert(e.message);
		}
	};

	$.extend($.ligerMethos.Grid, {
		selrow : function(idName) {
			//要注意到一点，这里的this就是ligerui对象
			var rowdata = this.getSelectedRow();
			if (!rowdata) {
				return null;
			} else
				return (rowdata[idName]);
		},
		selarrrow : function(idName) {
			var rows = grid.getCheckedRows();
			var str = "";
			$(rows).each(function() {
				str += this.demoId + ",";
			});
			str = str.replace(/,+$/, "");
			return str;
		}
	});
	function demoEntitySearch() {
		try {
			var gridManager = $("#maingrid4").ligerGetGridManager();
			var iv = $("#search_demoEntity_demoId").val();
			gridManager.setOptions({
				newPage : 1,
				parms : [ {
					name : 'filter_lt_demoId',
					value : iv
				} ]
			});
			gridManager.loadData(true);
		} catch (e) {
			alert(e.message);
		}

	}
	function clear_input_elements(containId) {
		$("#" + containId).find(':input').each(function() {
			switch (this.type) {
			case 'password':
			case 'select-multiple':
			case 'select-one':
			case 'text':
			case 'textarea':
				$(this).val('');
				break;
			case 'checkbox':
			case 'radio':
				this.checked = false;
			}
		});
	}
	function cleanDemoEntitySearch() {
		clear_input_elements("demoEntitySearchArea");
		demoEntitySearch();
	}
	function itemclick(item) {
		alert(item.text);
		grid.selarrrow("demoId");
	}

	var grid;
	$(function() {
		try {
			grid = $("#maingrid4").ligerGrid({
				columns : [ {
					display : '主键',
					name : 'demoId',
					align : 'right',
					width : 50,
					type : 'int'
				}, {
					display : '简单整数',
					name : 'intField',
					minWidth : 100,
					align : 'right',
					type : 'int'

				}, {
					display : '简单长整型',
					name : 'longField',
					minWidth : 100,
					align : 'right',
					type : 'int'
				}, {
					display : '简单短整数',
					name : 'shortField',
					minWidth : 100,
					align : 'right',
					type : 'int'
				}, {
					display : '简单字节类型',
					name : 'byteField',
					minWidth : 100,
					align : 'right',
					type : 'int'
				}, {
					display : '简单布尔类型',
					name : 'booleanField',
					minWidth : 100,

					type : 'boolean'

				}, {
					display : '简单字符类型',
					name : 'charField',
					minWidth : 100
				}, {
					display : '简单浮点型',
					name : 'floatField',
					minWidth : 100
				}, {
					display : '简单双精度',
					name : 'doubleField',
					minWidth : 100,
					type : "currency"
				}, {
					display : '对象整数',
					name : 'intObjField',
					minWidth : 100
				}, {
					display : '对象长整数',
					name : 'longObjField',
					minWidth : 100
				}, {
					display : '对象短整数',
					name : 'shortObjField',
					minWidth : 100
				}, {
					display : '对象字节类型',
					name : 'byteObjField',
					minWidth : 100
				}, {
					display : '对象布尔类型',
					name : 'booleanObjField',
					minWidth : 100,
					type : 'boolean'
				}, {
					display : '对象字符类型',
					name : 'charObjField',
					minWidth : 100
				}, {
					display : '对象单精度',
					name : 'floatObjField',
					minWidth : 100
				}, {
					display : '对象双精度',
					name : 'doubleObjField',
					minWidth : 100
				}, {
					display : '日期类型',
					name : 'dateField',
					minWidth : 100
				//,
				//type:"datetime"
				}, {
					display : '字符串',
					name : 'stringField',
					minWidth : 100
				}, {
					display : '大十进制',
					name : 'bigDecimalField',
					minWidth : 100
				}, {
					display : '时间戳',
					name : 'timestampField',
					minWidth : 100,
					type : "date"
				}

				],
				url : "demoEntityGrid",
				//dateFormat:"yyyy-MM-dd'T'HH:mm:ss",

				root : "pageList",
				record : "total",
				pageParmName : "page",
				pagesizeParmName : "pagesize",
				sortnameParmName : "sortname",
				sortorderParmName : "sortorder",

				usePager : true,
				pageSize : 50,
				sortName : 'demoId',
				pageSizeOptions : [ 10, 20, 30, 40, 50, 100, 200 ],
				showTitle : true,
				//title : '头部',
				rownumbers : true,
				width : '100%',
				height : '100%',
				checkbox : true,
				selectRowButtonOnly : false,
				allowUnSelectRow : false,
				alternatingRow : true,
				toolbar : {
					items : [ {
						text : '增加',
						click : demoEntityAdd,
						icon : 'add'
					}, {
						line : true
					}, {
						text : '修改',
						click : demoEntityEdit,
						icon : 'modify'
					}, {
						line : true
					}, {
						text : '删除',
						click : demoEntityDelete,
						icon : 'delete'
					}, {
						text : '查询',
						click : function() {
							$("#demoEntitySearchArea").toggle();
							grid.reRender();
						},
						icon : 'search'
					} ]
				}
			});
			$("#pageloading").hide();

		} catch (e) {
			alert(e.message);
		}
	});
</script>
<style type="text/css">
.l-button-inline
{
    display:inline;
    border: solid 1px #A3C0E8;
    overflow:hidden; 
    background: #E0EDFF url(${ctx}/images/controls/button-bg.gif) repeat-x center;
     text-align:center;color: #2C4D79;  text-decoration:none; cursor:pointer;
}
</style>
</head>
<body style="padding: 3px; overflow: hidden;">
	<div class="l-loading" style="display: block" id="pageloading"></div>
	<div  id="demoEntitySearchArea"
		style="display: none;" class="l-form">
		
		<s:textfield id="search_demoEntity_demoId"  cssClass="l-text"></s:textfield>
			<button id="search_demoEntity_button"
				onclick="javascript:demoEntitySearch();" class="l-button-inline">Search</button>
			<button id="clean_demoEntity_button"
				onclick="javascript:cleanDemoEntitySearch();" class="l-button-inline">Clean</button>
	</div>
	<!-- <div class="l-clear">说大声大声道</div> -->
	<div id="maingrid4" style="margin: 0; padding: 0"></div>
	<!-- <div style="display: none;"></div> -->
</body>
</html>
